package com.szeastroc.core.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.szeastroc.common.constant.Constant;
import com.szeastroc.common.utils.Result4Ajax;
import com.szeastroc.core.bean.system.SystemUser;

public class BaseController extends AbstractController{

    protected Logger logger = LoggerFactory.getLogger(getClass());

	public Result4Ajax success(){
        Result4Ajax result = new Result4Ajax();
        result.setCode(Constant.API_CODE_SUCCESS);
        result.setMsg(Constant.API_MSG_SUCCESS);
        return result;
    }

    public Result4Ajax success(Object data){
        Result4Ajax result = new Result4Ajax();
        result.setCode(Constant.API_CODE_SUCCESS);
        result.setMsg(Constant.API_MSG_SUCCESS);
        result.setData(data);
        return result;
    }

    public Result4Ajax error(){
        Result4Ajax result = new Result4Ajax();
        result.setCode(Constant.API_CODE_ERROR);
        result.setMsg(Constant.API_MSG_ERROR);
        return result;
    }

    public Result4Ajax error(String msg){
        Result4Ajax result = new Result4Ajax();
        result.setCode(Constant.API_CODE_ERROR);
        result.setMsg(msg);
        return result;
    }

    public Result4Ajax error(Integer code,String errorMsg){
        Result4Ajax result = new Result4Ajax();
        result.setCode(code);
        result.setMsg(errorMsg);
        return result;
    }

    public SystemUser getSessionUser(){
        return (SystemUser)SecurityUtils.getSubject().getSession().getAttribute("user");
    }


    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return null;
    }
    
}
